package com.ruoyi.cost.service.impl;

import com.ruoyi.balanceReturn.domain.HouseReturnT;
import com.ruoyi.cost.mapper.HouseCostTMapper;
import com.ruoyi.cost.service.IHouseCostTService;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.data.DataUtils;
import com.ruoyi.data.MD5;
import com.ruoyi.door.domain.HouseDoorT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 户管理Service业务层处理
 * 
 * @author lijie
 * @date 2023-04-20
 */
@Service
public class HouseCostTServiceImpl implements IHouseCostTService
{
    @Autowired
    private HouseCostTMapper houseCostTMapper;

    /**
     * 查询户管理
     * 
     * @param doorId 户管理主键
     * @return 户管理
     */
    @Override
    public HouseDoorT selectHouseDoorTByDoorId(Long doorId)
    {
        return houseCostTMapper.selectHouseDoorTByDoorId(doorId);
    }

    /**
     * 查询户管理列表
     * 
     * @param houseDoorT 户管理
     * @return 户管理
     */
    @Override
    public List<HouseDoorT> selectHouseDoorTList(HouseDoorT houseDoorT)
    {
        return houseCostTMapper.selectHouseDoorTList(houseDoorT);
    }

    @Override
    public HouseDoorT selectHouseDoorSum(HouseDoorT houseDoorT)
    {
        return houseCostTMapper.selectHouseDoorSum(houseDoorT);
    }

    /**
     * 修改户管理
     * 
     * @param houseDoorT 户管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateHouseDoorT(HouseDoorT houseDoorT)
    {

        HouseDoorT doorTempVO = new HouseDoorT();
        HouseCostT houseCostT = new HouseCostT();
        doorTempVO = houseCostTMapper.selectHouseDoorTByDoorId(houseDoorT.getDoorId());
        doorTempVO.setCreateDate(houseDoorT.getCostDate());
        doorTempVO.setUserName(houseDoorT.getUserName());
        doorTempVO.setTel(houseDoorT.getTel());
        doorTempVO.setPapersCode(MD5.md5(houseDoorT.getPapersCode()));
        doorTempVO.setCostDate(houseDoorT.getCostDate());
        doorTempVO.setBalance(DataUtils.sumMoney(doorTempVO.getBalance(), doorTempVO.getCostMoney()));
        int costId = houseCostTMapper.getCostId();
        houseCostT.setSerial(String.valueOf(costId+1));
        houseCostT.setCostDate(houseDoorT.getCostDate());
        houseCostT.setCreater(houseDoorT.getCreater());
        houseCostT.setRemark(houseDoorT.getRemark());
        houseCostT.setHouseId(houseDoorT.getHouseId());
        houseCostT.setCostMoney(doorTempVO.getCostMoney());
        houseCostTMapper.insertHouseCostT(houseCostT);
        houseCostTMapper.updateHouseDoorT(doorTempVO);
        return costId;
    }



}
